﻿using System;
using System.Collections.Generic;
using System.Text;
using HR.Appointments.DataLayer;

namespace HR.Appointments.Service
{
    /// <summary>
    /// Entity class for activites
    /// </summary>
    public class WorkstationEntity
    {
        #region Member variable
        private string _name;
        private int _companyId;
        private int _workstationId; 
        #endregion

        #region Constructors
        private WorkstationEntity(int workstationId, int companyId, string name)
        {
            _workstationId = workstationId;
            _companyId = companyId;
            _name = name;
        }

        #endregion

        #region Properties
        /// <summary>
        /// Name of the workstation
        /// </summary>
        public string Name
        {
            get
            {
                return _name; 
            }
            set
            {
                _name = value; 
            }
        }

        /// <summary>
        /// The company identifier
        /// </summary>
        public int CompanyId
        {
            get
            {
                return _companyId; 
            }
            set
            {
                _companyId = value; 
            }
        }

        /// <summary>
        /// The workstation identifier
        /// </summary>
        public int WorkstationId
        {
            get
            {
                return _workstationId; 
            }
            set
            {
                _workstationId = value; 
            }
        }
        #endregion

        #region Internal Methods
        /// <summary>
        /// Convert this object to datalayer 
        /// </summary>
        /// <param name="data">Datalayer entity</param>
        /// <returns>A datalayer entity with this objects values</returns>
		internal Workstation ToData(Workstation data)
        {
			if (data == null)
			{
				data = new Workstation();
			}
            data.CompanyId = _companyId;
            data.Name = _name;
            return data;
            //data.Username
        }
        #endregion

        #region Override Methods
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType()) return false;
            WorkstationEntity eql = (WorkstationEntity)obj;
            return (eql._workstationId == _workstationId);
        }

        /// <summary>
        /// Serves as a hash function for a this type.
        /// </summary>
        /// <returns>A hash code for the current Object.</returns>
        public override int GetHashCode()
        {
            return _workstationId.GetHashCode();
        }

        /// <summary>
        /// Returns a String that represents the current Object.
        /// </summary>
        /// <returns>A String that represents the current Object.</returns>
        public override string ToString()
        {
            return _workstationId.ToString() + " " + _name;
        }
        #endregion


        #region Static Methods
        /// <summary>
        /// Loads a datalayer entity into a service entity.
        /// </summary>
        /// <param name="row"></param>
        /// <returns>A loaded entity</returns>
        internal static WorkstationEntity Load(HR.Appointments.DataLayer.Workstation row)
        {
            if (row == null) return null;
            return new WorkstationEntity(row.WorkstationId, row.CompanyId, row.Name);
        }

        /// <summary>
        /// Creates a new entity
        /// </summary>
        /// <param name="companyId">Company identifier</param>
        /// <param name="name">Name of the workstation</param>
        /// <returns></returns>
        public static WorkstationEntity Create(int companyId, string name)
        {
            return new WorkstationEntity(0, companyId, name);
        }
        #endregion
    }
}
